<extend name="Layout/ins_page" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	<select name="dept_list" id="dept_list" class="hidden">
		{:fill_option($dept_list)}
	</select>
	{:W('PageHeader/search',array('name'=>'用户管理','search'=>'S'))}
	<div class="oprator-panel">
		<label class="layui-form-label col-6">状态:</label>
		<div class="layui-input-inline x-select col-10" >
			<form method="post" id="form_adv_search" name="form_adv_search" method="post" >
				<select id="eq_is_del" name="eq_is_del" class="layui-input" >
					<option value="0">启用</option>
					<option value="1">禁用</option>
					<option value="2">其他</option>
				</select>
			</form>
		</div>
		<php>
			if(C('LDAP_LOGIN')){
		</php>
		<a onclick="ad_sync()" class="btn btn-sm btn-primary">从LDAP导入</a>
		<php>
			}
		</php>
		<php>
			if($auth['admin']){
		</php>
		<a id="btn_import_user" class="btn">导入</a>
		<a id="btn_weixin_sync" class="hidden btn">同步到微信</a>
		<php>
			}
		</php>
		<a id="btn_reset_password" class="btn">设置密码</a>
		<a id="btn_clear_salary_password" class="btn">清空工资密码</a>

		<div class="split"></div>
		<a id="btn_add" class="btn">新增</a>
		<a id="btn_save"  class="btn">保存</a>
		<span class="l">|</span>
		<a id="btn_del"  class="btn btn-del">删除</a>
	</div>

	<div class="sub-frame">
		<div class="sub-sidebar white">
			<form id="form_user" name="form_data" method="post" class="">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th class="col-3 x-checkbox">
							<input type="checkbox" class="toggle-select-all" data="user_id[]"  />
							</th>
							<th>员工编号</th>
							<th>姓名</th>
							<th>状态</th>
						</tr>
					</thead>
					<tbody>
						<volist name="list" id="data">
							<tr id="{$data.id}" class="tbody">
								<td class="text-center col-3 x-checkbox">
								<input type="checkbox" name="user_id[]" value="{$data.id}" />
								</td>
								<td class="click">{$data.emp_no}</td>
								<td class="click">{$data.name}</td>
								<td class="click">{$data.is_del|status}</td>
							</tr>
						</volist>
					</tbody>
				</table>
			</form>
			<div class="pagination">
				{$page}
			</div>
		</div>
		<div class="sub-content gray">
			<form id="form_data" name="form_data" method="post" >
				<input type="hidden" id="save_name" name="save_name">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="signature" id="signature" >
				<input type="hidden" name="opmode" id="opmode" value="edit">
				<div>
					<div>
						<div class="layui-sub-form-item">
							<div class="layui-input-block">
								<img id="pic" class="avtar" src="">
								<a id="btn_select_avatar" class="btn">修改头像</a>
							</div>
						</div>
						<hr style="clear: none">
						<div class="layui-sub-form-item">
							<label class="layui-form-label">员工编号*：</label>
							<div class="layui-input-block col-16">
								<input class="layui-input" type="text" id="emp_no" name="emp_no"  check="required" info="请输入员工编号" readonly="readonly" style="background:#f5f5f5;">
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">姓名*：</label>
							<div class="layui-input-block col-16">
								<input class="layui-input" type="text" id="name" name="name"  check="required" info="请输入姓名" >
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">性别*：</label>
							<div class="layui-input-block col-10 x-select">
								<select name="sex" id="sex" class="layui-input">
									<option  value="male">男</option>
									<option value="female">女</option>
								</select>
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">生日*：</label>
							<div class="layui-input-block">
								<input  type="text" id="birthday" name="birthday"  class="input-date layui-input" >
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">部门*：</label>
							<div class="layui-input-block  col-19">
								<input class="layui-input" name="dept_name"  id="dept_name" type="text" info="请选择部门" check="required"  />
								<input name="dept_id" id="dept_id" type="hidden" />
								<div class="input-group-btn">
									<a class="add-on" id="btn_select_dept"> <i class="fa fa-search" ></i> </a>
								</div>
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">职位*：</label>
							<div class="layui-input-block col-19 x-select">
								<select name="position_id" id="position_id" class="layui-input" info="请选择职位" check="required">
									<option value="">选择职位</option>
									{:fill_option($position_list)}
								</select>
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">办公室电话*：</label>
							<div class="layui-input-block col-19">
								<input type="text" id="office_tel" name="office_tel" class="layui-input">
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">移动电话*：</label>
							<div class="layui-input-block col-19">
								<input type="text" id="mobile_tel" name="mobile_tel" class="layui-input">
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">电子邮箱*：</label>
							<div class="layui-input-block">
								<input type="text" id="email" name="email" class="layui-input">
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">负责业务*：</label>
							<div class="layui-input-block">
								<input type="text" id="duty" name="duty" class="layui-input">
							</div>
						</div>
						<div class="layui-sub-form-item">
							<label class="layui-form-label">状态*：</label>
							<div class="layui-input-block col-10 x-select">
								<select class="layui-input"  name="is_del" id="is_del">
									<option  value="0">启用</option>
									<option value="1">禁用</option>
								</select>
							</div>
						</div>
						<p class="text-right">
							带*项为必填选项
						</p>
					</div>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script>
		layui.use('global', function() {
			var $ = layui.jquery;
			set_return_url(null);
			set_val('eq_is_del', '{$eq_is_del}');

			$(".sub-sidebar tbody td.click").click(function() {
				$(".sub-sidebar tbody tr.active").removeClass("active");
				$tr = $(this).parent();
				$tr.addClass("active");
				if ($(".sub-sidebar tbody tr.active input:checked").length == 0) {
					$(".sub-sidebar tbody tr.active input").prop('checked', true);
				} else {
					$(".sub-sidebar tbody tr.active input").prop('checked', false);
				}
				send_ajax("{:U('read')}", "id=" + $tr.attr("id"), function(data) {
					showdata(data);
				});
				return false;
			});

			function showdata(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				var dept_id = $("#dept_id").val();
				var dept_name = $("#dept_list option[value='" + dept_id + "']").text();
				$("#dept_name").val(dept_name);
				$('#pic').attr('src', result.data.pic);
				$("#save_name").val("");
				$("#opmode").val("edit");
			};

			$("#btn_add").on('click', function() {
				winopen("{:U('add')}", 560, 470);
			});

			$("#btn_save").on('click', function() {
				send_form("form_data", "{:U('save')}", "{:U('index')}", function(ret) {
					if (ret.status) {
						layer.msg(ret.info, {
							time : 1200
						}, function() {
							location.reload(true);
						});
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});
			$('#btn_select_avatar').on('click', function() {
				if ($("#id").val().length == 0) {
					layer.msg("请选择用户");
					return false;
				}
				winopen("{:U('popup/avatar')}?id=" + $("#id").val(), 560, 470);
			});
			$('#btn_select_dept').on('click', function() {
				if ($("#id").val().length < 1) {
					layer.msg("请选择用户");
					return false;
				}
				winopen("{:U('select_dept')}", 560, 470);
			});
			$('#btn_del').on('click', function() {
				if ($("input[name='user_id[]']:checked").length == 0) {
					layer.msg('请选择要删除的人员 ');
					return;
				}
				//信息框-例2
				layer.msg('确定要删除吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_user").serialize();
						send_ajax("{:U('del')}", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, {
									time : 1200
								}, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});
			$('#btn_clear_salary_password').on('click', function() {
				if ($("input[name='user_id[]']:checked").length == 0) {
					layer.msg('请选择要清空密码的人员 ');
					return;
				}
				var vars = $("#form_user").serialize();
				layer.msg('确定要清空密码吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						send_ajax("{:U('del_pwd')}", vars, function(data) {
							if (data.status) {
								layer.msg(data.info, {
									time : 1200
								}, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});
			$("#btn_reset_password").on('click', function() {
				if ($("input[name='user_id[]']:checked").length == 0) {
					layer.msg('请选择要修改密码的人员 ');
					return;
				}
				winopen("{:U('password')}", 560, 470);
			});
			$("#btn_import_user").on('click', function() {
				window.open("{:U('import')}", "_self");
				return false;
			});
			$("#eq_is_del").on('change', function() {
				$("#form_adv_search").submit();
			});
		});
	</script>
	<script type="text/javascript">
		function weixin_sync() {
			winopen("{:U('weixin_sync')}", 560, 470);
		}

		function ad_sync() {
			winopen("{:U('ad_sync')}", 730, 500);
		}
	</script>
</block>
